package Test02;

import java.util.Random;

//在数组中生成随机数并求和以及平均数
public class test02 {
    public static void main(String[] args) {
        int[] arr = new int[10];
        int sum = 0;
        double avg = 0.0;
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt(100) + 1;
            //求和
            sum = sum + arr[i];
        }
        //遍历数组
        System.out.print("遍历数组：");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

        System.out.println();
        //求平均数
        avg = (double) sum / arr.length;
        System.out.println("数组的和为：" + sum);
        System.out.println("数组的平均值为：" + avg);

        //统计有多少个数据比平均数小
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] < avg) {
                count++;
            }
        }
        System.out.println("有" + count + "个数据比平均数小");

    }
}
